package easy.验证回文串;


class Solution {
    public boolean isPalindrome(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                stringBuilder.append(Character.toLowerCase(ch));
            }
        }
        StringBuilder reverseStr = new StringBuilder(stringBuilder).reverse();
        //输出字符串.toString()，而不是地址
        return stringBuilder.toString().equals(reverseStr.toString());
    }

    public static void main(String[] args) {
        String s = "A man, a plan, a canal: Panama";
        String s2 = "race a car";
        Solution solution = new Solution();
        System.out.println(solution.isPalindrome(s));
        System.out.println(solution.isPalindrome(s2));
    }
}